package com.leyou.mapper;

import com.leyou.common.mapper.BaseMapper;
import com.leyou.entity.Brand;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

//品牌管理
public interface BrandMapper extends BaseMapper<Brand> {
    /**
     * 新增商品分类和品牌中间表数据
     * @param cids 商品分类id集合
     * @param bid 品牌id
     * @return 新增的条数
     */
    int insertCategoryBrand(@Param("bid") Long bid, @Param("cids") List<Long> cids);

    /**
     *
     * @param id
     */
    @Delete("DELETE from tb_category_brand WHERE brand_id = #{bid}")
    void deleteCategoryBrand(@Param("bid")Long bid);

    /**
     * 根据分类查询品牌
     * @param cid
     * @return
     */
    @Select("SELECT b.id, b.name, b.letter, b.image FROM tb_category_brand cb INNER JOIN tb_brand b ON b.id = cb.brand_id WHERE cb.category_id = #{cid}")
    List<Brand> queryByCategoryId(@Param("cid") Long cid);
}
